home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch13 / Oblique.frm (.txt) < prev    next >
Visual Basic Form  |  1999-06-19  |  7KB  |  215 lines

  1. VERSION 5.00
  2. Begin VB.Form frmOblique 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H00C0C0C0&
  5.    Caption         =   "Oblique"
  6.    ClientHeight    =   3180
  7.    ClientLeft      =   975
  8.    ClientTop       =   1815
  9.    ClientWidth     =   7470
  10.    BeginProperty Font 
  11.       Name            =   "MS Sans Serif"
  12.       Size            =   8.25
  13.       Charset         =   0
  14.       Weight          =   700
  15.       Underline       =   0   'False
  16.       Italic          =   0   'False
  17.       Strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    KeyPreview      =   -1  'True
  21.    LinkTopic       =   "Form1"
  22.    PaletteMode     =   1  'UseZOrder
  23.    ScaleHeight     =   3180
  24.    ScaleWidth      =   7470
  25.    Begin VB.TextBox txtAngle 
  26.       Height          =   285
  27.       Left            =   480
  28.       TabIndex        =   7
  29.       Text            =   "30"
  30.       Top             =   0
  31.       Width           =   495
  32.    End
  33.    Begin VB.PictureBox picCabinet 
  34.       AutoRedraw      =   -1  'True
  35.       Height          =   2415
  36.       Left            =   5040
  37.       ScaleHeight     =   -6
  38.       ScaleLeft       =   -3
  39.       ScaleMode       =   0  'User
  40.       ScaleTop        =   3
  41.       ScaleWidth      =   6
  42.       TabIndex        =   2
  43.       Top             =   360
  44.       Width           =   2415
  45.    End
  46.    Begin VB.PictureBox picCavalier 
  47.       AutoRedraw      =   -1  'True
  48.       Height          =   2415
  49.       Left            =   2520
  50.       ScaleHeight     =   -6
  51.       ScaleLeft       =   -3
  52.       ScaleMode       =   0  'User
  53.       ScaleTop        =   3
  54.       ScaleWidth      =   6
  55.       TabIndex        =   1
  56.       Top             =   360
  57.       Width           =   2415
  58.    End
  59.    Begin VB.PictureBox picOrthographic 
  60.       AutoRedraw      =   -1  'True
  61.       Height          =   2415
  62.       Left            =   0
  63.       ScaleHeight     =   -6
  64.       ScaleLeft       =   -3
  65.       ScaleMode       =   0  'User
  66.       ScaleTop        =   3
  67.       ScaleWidth      =   6
  68.       TabIndex        =   0
  69.       Top             =   360
  70.       Width           =   2415
  71.    End
  72.    Begin VB.Label Label1 
  73.       Caption         =   "Angle"
  74.       BeginProperty Font 
  75.          Name            =   "MS Sans Serif"
  76.          Size            =   8.25
  77.          Charset         =   0
  78.          Weight          =   400
  79.          Underline       =   0   'False
  80.          Italic          =   0   'False
  81.          Strikethrough   =   0   'False
  82.       EndProperty
  83.       Height          =   255
  84.       Index           =   3
  85.       Left            =   0
  86.       TabIndex        =   6
  87.       Top             =   0
  88.       Width           =   495
  89.    End
  90.    Begin VB.Label Label1 
  91.       Alignment       =   2  'Center
  92.       Caption         =   "Cabinet"
  93.       Height          =   255
  94.       Index           =   2
  95.       Left            =   5040
  96.       TabIndex        =   5
  97.       Top             =   2880
  98.       Width           =   2415
  99.    End
  100.    Begin VB.Label Label1 
  101.       Alignment       =   2  'Center
  102.       Caption         =   "Cavalier"
  103.       Height          =   255
  104.       Index           =   1
  105.       Left            =   2520
  106.       TabIndex        =   4
  107.       Top             =   2880
  108.       Width           =   2415
  109.    End
  110.    Begin VB.Label Label1 
  111.       Alignment       =   2  'Center
  112.       Caption         =   "Orthographic"
  113.       Height          =   255
  114.       Index           =   0
  115.       Left            =   0
  116.       TabIndex        =   3
  117.       Top             =   2880
  118.       Width           =   2415
  119.    End
  120. Attribute VB_Name = "frmOblique"
  121. Attribute VB_GlobalNameSpace = False
  122. Attribute VB_Creatable = False
  123. Attribute VB_PredeclaredId = True
  124. Attribute VB_Exposed = False
  125. Option Explicit
  126. ' Location of viewing eye.
  127. Private EyeR As Single
  128. Private EyeTheta As Single
  129. Private EyePhi As Single
  130. ' Location of focus point.
  131. Private Const FocusX = 0#
  132. Private Const FocusY = 0#
  133. Private Const FocusZ = 0#
  134. Private Projector(1 To 4, 1 To 4) As Single
  135. Private CavProj(1 To 4, 1 To 4) As Single
  136. Private CabProj(1 To 4, 1 To 4) As Single
  137. ' Transform and draw the data.
  138. Private Sub DrawData()
  139. Dim angle As Single
  140.     ' Get the angle.
  141.     On Error Resume Next
  142.     angle = CSng(txtAngle.Text)
  143.     If Err.Number <> 0 Then
  144.         angle = 30
  145.         txtAngle.Text = "30"
  146.     End If
  147.     angle = angle * PI / 180
  148.     ' Create the projection matrices.
  149.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  150.     m3ObliqueXY CavProj, 1#, angle
  151.     m3ObliqueXY CabProj, 0.5, angle
  152.     ' Project and draw the data.
  153.     TransformAllData Projector
  154.     DrawAllData picOrthographic, ForeColor, True
  155.     TransformAllData CavProj
  156.     DrawAllData picCavalier, ForeColor, True
  157.     TransformAllData CabProj
  158.     DrawAllData picCabinet, ForeColor, True
  159. End Sub
  160. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  161. Const Dtheta = PI / 20
  162.     Select Case KeyCode
  163.         Case vbKeyLeft
  164.             EyeTheta = EyeTheta - Dtheta
  165.         
  166.         Case vbKeyRight
  167.             EyeTheta = EyeTheta + Dtheta
  168.         
  169.         Case vbKeyUp
  170.             EyePhi = EyePhi - Dtheta
  171.         
  172.         Case vbKeyDown
  173.             EyePhi = EyePhi + Dtheta
  174.         
  175.         Case Else
  176.             Exit Sub
  177.     End Select
  178.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  179.     TransformAllData Projector
  180.     DrawAllData picOrthographic, ForeColor, True
  181. End Sub
  182. Private Sub Form_Load()
  183.     ' Initialize the eye position.
  184.     EyeR = 3
  185.     EyeTheta = PI * 0.4
  186.     EyePhi = PI * 0.1
  187.     ' Create the data.
  188.     CreateData
  189.     ' Draw the data.
  190.     DrawData
  191. End Sub
  192. Private Sub CreateData()
  193.     ' Create the axes.
  194.     MakeSegment 0, 0, 0, 3, 0, 0    ' X axis.
  195.     MakeSegment 0, 0, 0, 0, 3, 0    ' Y axis.
  196.     MakeSegment 0, 0, 0, 0, 0, 3    ' Z axis.
  197.     ' Create the object to display.
  198.     MakeSegment 0, 0, 0, 2, 0, 0
  199.     MakeSegment 2, 0, 0, 2, 2, 0
  200.     MakeSegment 2, 2, 0, 0, 2, 0
  201.     MakeSegment 0, 2, 0, 0, 0, 0
  202.     MakeSegment 0, 0, 2, 2, 0, 2
  203.     MakeSegment 2, 0, 2, 2, 2, 2
  204.     MakeSegment 2, 2, 2, 0, 2, 2
  205.     MakeSegment 0, 2, 2, 0, 0, 2
  206.     MakeSegment 0, 0, 0, 0, 0, 2
  207.     MakeSegment 2, 0, 0, 2, 0, 2
  208.     MakeSegment 2, 2, 0, 2, 2, 2
  209.     MakeSegment 0, 2, 0, 0, 2, 2
  210. End Sub
  211. ' Redraw the data.
  212. Private Sub txtAngle_Change()
  213.     DrawData
  214. End Sub
  215.